(function () {
	
	nsbase.views.news = new NewsFunc();

	function NewsFunc () {
		var _self = this;

    	_self.init = init;


    	var newsActions = nsbase.config.actionUrl.news,
    		  utilities = nsbase.utility;

      var cssClass = {
        selected:"selected"
      };
    	function init () {
        $(".nav_menu li.News").addClass(cssClass.selected);
    		initNewsWall();
    	}

    	function initNewsWall () {
    		var $newsWallContainer = $(".newsWall");
    		var pageConfig = {
                container: $newsWallContainer,
                remote:true,
                actionUrl:newsActions.getNewsList,
                actionParams:{},
                pageSize:5,
                pageHandler:function (results){ 
                    bindNewsWall($newsWallContainer,results);
                }
            }
			var pageBar = new nsbase.controls.pageBar(pageConfig);
    	}

    	function bindNewsWall (container,results) {
  			if(!results || results.length == 0){
  				return;
  			}
  			var newsTmpl = $("#tmplContainer").html();
  			var $newsItemContainer = container.find('ul');
        $newsItemContainer.empty();
  			$.each(results, function(index, newsInfo) {
  				var $itemContainer = $("<li></li>");
  				container.find('ul').append($itemContainer);

  				var $newsItem = $(utilities.tmplFormat(newsTmpl,newsInfo,newFormat));
  				var $newsPic = $newsItem.find("img[src-path]");
				  $newsPic.attr("src",$newsPic.attr("src-path"));
				  $newsPic.removeAttr("src-path");
				  $itemContainer.append($newsItem);

  			});
  			

    	}

    	function newFormat (newsInfo,dataIndex) {
        if(dataIndex == "newsContent"){
          var originalContent = $(newsInfo.newsContent).text();
          var newContent = $.trim(originalContent).substr(0,200)+"...";
          return newContent;
        }
    	}


	}
})();